import React from 'react';
import { createStackNavigator, createSwitchNavigator } from 'react-navigation';
import { View } from 'react-native';
import px from '../utils/px';
import GlobalStyles from '../style/GlobalStyles';
import BackIcon from '../components/base/BackIcon';
import HomeScreen from '../container/HomeScreen';
import LoginScreen from '../container/LoginScreen';
import AgreementScreen from '../container/AgreementScreen';
import VersionScreen from '../container/VersionScreen';
import VersionLoadingScreen from '../container/VersionLoadingScreen';
import LoginLoadingScreen from '../container/LoginLoadingScreen';

import ParityListScreen from '../container/ParityListScreen';

// 版本控制页面
const UpdateStack = createStackNavigator({
    Version: VersionScreen
}, {
    initialRouteName: 'Version'
});

// 未登录用户页面
const AuthStack = createStackNavigator({
    Login: LoginScreen,
    Agreement: AgreementScreen
}, {
    initialRouteName: 'Login',
    defaultNavigationOptions: {
        headerStyle: {
            elevation: 0
        },
        headerBackImage: <BackIcon/>,
        headerTitleStyle: {
            flex: 1,
            fontFamily: GlobalStyles.FONT_FAMILY_NORMAL,
            fontSize: px(36),
            justifyContent: 'center',
            alignItems: 'center',
            textAlign: 'center',
            fontWeight: 'normal'
        },
        headerRight: <View/>
    }
});

/**
 * 项目路由说明
 *    1. App 启动首先加载 Splash 页面, 防止白屏
 *    2. Splash (暂时未加入欢迎页 -- 后期有需求添加)
 *             -> VersionLoading 是否有版本更新
 *                True: -> Version 进行版本更新
 *                False: -> LoginLoading 用户是否登录
 *                          True: -> AppStack 主页
 *                          False: -> Login 登录注册页面
 *
 * 业务逻辑页面添加到 AppStack 里面
 * AppStack Start
 */
const AppStack = createStackNavigator({
    Home: {
        screen: HomeScreen
    },
    ParityList: {
        screen: ParityListScreen
    }
}, {
    initialRouteName: 'Home'
});
/* AppStack End */

// 主路由入口
const IndexSwitch = createSwitchNavigator({
    LoginLoading: LoginLoadingScreen,
    App: AppStack,
    Auth: AuthStack
}, {
    initialRouteName: 'LoginLoading'
});

export default createSwitchNavigator({
    VersionLoading: VersionLoadingScreen,
    Index: IndexSwitch,
    Update: UpdateStack
}, {
    initialRouteName: 'VersionLoading'
});
